package com.example.demo.mapper;

import com.example.demo.po.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface UserMapper {
    User selectById(Long id);

    List<User> selectAll();

    int insert(User user);

    int update(User user);

    int deleteById(Long id);

    User getByPhone(String phone);

    @Select("<script>" +
            "SELECT * FROM users u " +
            "<if test='includeDept'>" +
            "LEFT JOIN departments d ON u.dept_id = d.id" +
            "</if>" +
            "WHERE u.id = #{id}" +
            "</script>")
    User selectByIdWithDept(@Param("id") Long id, @Param("includeDept") boolean includeDept);

    List<User> selectPage(int offset, int size);
}